﻿#region --- 文件注释 ---
//-----------------------------------------------------------------------------
// Game.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region --- 命名空间 ---

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using BNB7.Entry.IniData;

#endregion

namespace BNB7
{
    public class BNB7Game : Microsoft.Xna.Framework.Game
    {
        #region --- 成员变量 --- 

        GraphicsDeviceManager graphics;
        ScreenManager screenManager;

        #endregion

        #region --- 单例实现 ---

        private static BNB7Game instance = null;
        private static readonly object locker = new object();

        public static BNB7Game Instance
        {
            get
            {
                return instance;
            }
        }

        #endregion

        #region --- 初始化 ---

        /// <summary>
        /// The main game constructor.
        /// </summary>
        public BNB7Game()
        {
            instance = this;

            //InitClass.Init();
            Content.RootDirectory = "Content";

            graphics = new GraphicsDeviceManager(this);
            TargetElapsedTime = TimeSpan.FromTicks(223333);


            InitializeGraphics();

            // Create the screen manager component.
            screenManager = new ScreenManager(this);


            Components.Add(screenManager);

            // attempt to deserialize the screen manager from disk. if that
            // fails, we add our default screens.
            if (!screenManager.DeserializeState())
            {
                // Activate the first screens.
#if WINDOWS_PHONE
                screenManager.AddScreen(new BackgroundScreen(), null);
                screenManager.AddScreen(new MainMenuScreen(), null);
#endif

#if WINDOWS
                screenManager.AddScreen(new GameplayScreen(), null);
#endif
            }
        }

        protected override void OnExiting(object sender, System.EventArgs args)
        {
            // serialize the screen manager whenever the game exits
            screenManager.SerializeState();

            base.OnExiting(sender, args);
        }

        /// <summary>
        /// 
        /// </summary>
        private void InitializeGraphics()
        {
#if WINDOWS_PHONE
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 480;
            graphics.IsFullScreen = true;
#endif

#if WINDOWS
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
#endif
        }

        #endregion

        #region --- Draw ---

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.Black);

            // The real drawing happens inside the screen manager component.
            base.Draw(gameTime);
        }

        #endregion
    }

    #region --- 程序入口 ---

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static class Program
    {
        static void Main()
        {
            using (BNB7Game game = new BNB7Game())
            {
                game.Run();
            }
        }
    }

    #endregion
}
